package cn.wen.eeayjoke.adapter.home;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.HashMap;
import java.util.Map;

import cn.wen.eeayjoke.MainFmt;
import cn.wen.eeayjoke.ui.home.GoodsCategoryFmt;
import cn.wen.eeayjoke.ui.home.HomeFmt;
import cn.wen.eeayjoke.ui.home.ManagerCenterFmt;
import cn.wen.eeayjoke.ui.home.ShopCarFmt;

/**
 * HomeActivity ViewPager的Adapter
 */

public class HomeFmtPagerAdapter extends FragmentPagerAdapter {
    private Map<Integer, Fragment> mFragments;

    public HomeFmtPagerAdapter(FragmentManager fm) {
        super(fm);
        mFragments = new HashMap<>(5);
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = mFragments.get(position);
        if (fragment != null) {
            return fragment;
        }
        switch (position) {
            case 0:
                fragment = new HomeFmt();
                break;
            case 1:
                fragment = new GoodsCategoryFmt();
                break;
            case 2:
                fragment = new ManagerCenterFmt();
                break;
            case 3:
                fragment = new ShopCarFmt();
                break;
            case 4:
                fragment = new MainFmt();
                break;

        }
        mFragments.put(position, fragment);
        return fragment;
    }

    @Override
    public int getCount() {
        return 5;
    }
}
